---
layout: "default"
title: "Array"
description: "Swift documentation for 'Array': Conceptually, Array is an efficient, tail-growable random-access."
keywords: "Array,struct,swift,documentation,append,extend,filter,flatMap,generate,getMirror,insert,join,map,reduce,removeAll,removeAtIndex,removeLast,removeRange,replaceRange,reserveCapacity,reverse,sort,sorted,splice,withUnsafeBufferPointer,withUnsafeMutableBufferPointer,capacity,count,debugDescription,description,endIndex,first,isEmpty,last,startIndex,Element,SubSlice,Generator,Index,SubSequence"
root: "/v1.2"
---

<div class="intro-declaration"><code class="language-swift">struct Array&lt;T&gt;</code></div>

<div class="discussion comment">
    <p>Conceptually, <code>Array</code> is an efficient, tail-growable random-access
collection of arbitrary elements.</p>

<h1>Common Properties of Array Types</h1>

<p>The information in this section applies to all three of Swift&#39;s
array types, <code>Array&lt;T&gt;</code>, <code>ContiguousArray&lt;T&gt;</code>, and <code>ArraySlice&lt;T&gt;</code>.
When you read the word &quot;array&quot; here in a normal typeface, it
applies to all three of them.</p>

<h2>Value Semantics</h2>

<p>Each array variable, <code>let</code> binding, or stored property has an
independent value that includes the values of all of its elements.
Therefore, mutations to the array are not observable through its
copies:</p>

<pre><code class="language-swift">var a = [1, 2, 3]
var b = a
b[0] = 4
println(&quot;a=\(a), b=\(b)&quot;)     // a=[1, 2, 3], b=[4, 2, 3]</code></pre>

<p>(Of course, if the array stores <code>class</code> references, the objects
are shared; only the values of the references are independent)</p>

<p>Arrays use Copy-on-Write so that their storage and elements are
only copied lazily, upon mutation, when more than one array
instance is using the same buffer.  Therefore, the first in any
sequence of mutating operations may cost <code>O(N)</code> time and space,
where <code>N</code> is the length of the array.</p>

<h2>Growth and Capacity</h2>

<p>When an array&#39;s contiguous storage fills up, new storage must be
allocated and elements must be moved to the new storage.  <code>Array</code>,
<code>ContiguousArray</code>, and <code>ArraySlice</code> share an exponential growth
strategy that makes <code>append</code> a constant time operation <em>when
amortized over many invocations</em>.  In addition to a <code>count</code>
property, these array types have a <code>capacity</code> that reflects their
potential to store elements without reallocation, and when you
know how many elements you&#39;ll store, you can call
<code>reserveCapacity</code> to pre-emptively reallocate and prevent
intermediate reallocations.</p>

<h1>Objective-C Bridge</h1>

<p>The main distinction between <code>Array</code> and the other array types is
that it interoperates seamlessly and efficiently with Objective-C.</p>

<p><code>Array&lt;T&gt;</code> is considered bridged to Objective-C iff <code>T</code> is bridged
to Objective-C.</p>

<p>When <code>T</code> is a <code>class</code> or <code>@objc</code> protocol type, <code>Array</code> may store
its elements in an <code>NSArray</code>.  Since any arbitrary subclass of
<code>NSArray</code> can become an <code>Array</code>, there are no guarantees about
representation or efficiency in this case (see also
<code>ContiguousArray</code>).  Since <code>NSArray</code> is immutable, it is just as
though the storage was shared by some copy: the first in any
sequence of mutating operations causes elements to be copied into
unique, contiguous storage which may cost <code>O(N)</code> time and space,
where <code>N</code> is the length of the array (or more, if the underlying
<code>NSArray</code> is has unusual performance characteristics).</p>

<h2>Bridging to Objective-C</h2>

<p>Any bridged <code>Array</code> can be implicitly converted to an <code>NSArray</code>.
When <code>T</code> is a <code>class</code> or <code>@objc</code> protocol, bridging takes O(1)
time and O(1) space.  Other <code>Array</code>s must be bridged
element-by-element, allocating a new object for each element, at a
cost of at least O(<code>count</code>) time and space.</p>

<h2>Bridging from Objective-C</h2>

<p>An <code>NSArray</code> can be implicitly or explicitly converted to any
bridged <code>Array&lt;T&gt;</code>.  This conversion calls <code>copyWithZone</code> on the
<code>NSArray</code>, to ensure it won&#39;t be modified, and stores the result
in the <code>Array</code>.  Type-checking, to ensure the <code>NSArray</code>&#39;s
elements match or can be bridged to <code>T</code>, is deferred until the
first element access.</p>
</div>

<table class="standard">
<tr>
<th id="inheritance">Inheritance</th>
<td>
<code class="inherits">ArrayLiteralConvertible, CollectionType, DebugPrintable, ExtensibleCollectionType, MutableCollectionType, MutableSliceable, Printable, RangeReplaceableCollectionType, Reflectable, SequenceType, Sliceable, _ArrayType, _CollectionType, _DestructorSafeContainer, _ExtensibleCollectionType, _SequenceType, _Sequence_Type, _Sliceable, __ArrayType</code>
<span class="viz"><a href="hierarchy/">View Protocol Hierarchy &rarr;</a></span>
</td>
</tr>

<tr>
<th id="aliases">Associated Types</th>
<td>
<span id="aliasesmark"></span>
<div class="declaration">
<code class="language-swift">Element = T</code>
<div class="comment">
    <p>The type of element stored by this <code>Array</code></p>
</div>
</div>
<div class="declaration">
<code class="language-swift">SubSlice = ArraySlice&lt;T&gt;</code>
<div class="comment">
    <p>A type that can represent a sub-range of an <code>Array</code> </p>
</div>
</div>
<div class="declaration">
<code class="language-swift">Generator = IndexingGenerator&lt;[T]&gt;</code>
<div class="comment">
    <p><em>Type alias inferred.</em></p>
</div>
</div>
<div class="declaration">
<code class="language-swift">Index = Int</code>
<div class="comment">
    <p><em>Type alias inferred.</em></p>
</div>
</div>
<div class="declaration">
<code class="language-swift">SubSequence = ArraySlice&lt;T&gt;</code>
<div class="comment">
    <p><em>Type alias inferred.</em></p>
</div>
</div>
</td>
</tr>


<tr>
<th>Import</th>
<td><code class="language-swift">import Swift</code></td>
</tr>

</table>


<h3>Initializers</h3>
<div class="declaration" id="init">
<a class="toggle-link" data-toggle="collapse" href="#comment-init">init()</a><div class="comment collapse" id="comment-init"><div class="p">
    <p>Construct an empty Array</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init()</code>

    </div></div>
</div>
<div class="declaration" id="init_-arraybuffer-t">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_-arraybuffer-t">init(<wbr>_: _ArrayBuffer&lt;T&gt;)</a><div class="comment collapse" id="comment-init_-arraybuffer-t"><div class="p">
    <p>Initialization from an existing buffer does not have &quot;array.init&quot;
semantics because the caller may retain an alias to buffer.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init(_ buffer: _ArrayBuffer&lt;T&gt;)</code>

    </div></div>
</div>
<div class="declaration" id="init-s_-sequencetype-where-t-t_-s">
<a class="toggle-link" data-toggle="collapse" href="#comment-init-s_-sequencetype-where-t-t_-s"><wbr>init&lt;S : SequenceType where T == T&gt;(<wbr>_: S)</a><div class="comment collapse" id="comment-init-s_-sequencetype-where-t-t_-s"><div class="p">
    <p>Construct from an arbitrary sequence with elements of type <code>T</code></p>

    <h4>Declaration</h4>    
    <code class="language-swift">init&lt;S : SequenceType where T == T&gt;(_ s: S)</code>

    </div></div>
</div>
<div class="declaration" id="init-fromcocoaarray_nocopy_">
<a class="toggle-link" data-toggle="collapse" href="#comment-init-fromcocoaarray_nocopy_">init(<wbr>_fromCocoaArray:<wbr>noCopy:)</a><div class="comment collapse" id="comment-init-fromcocoaarray_nocopy_"><div class="p">
    <p>Construct from the given <code>_NSArrayCoreType</code>.</p>

<p>If <code>noCopy</code> is <code>true</code>, either <code>source</code> must be known to be immutable,
or the resulting <code>Array</code> must not survive across code that could mutate
<code>source</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init(_fromCocoaArray source: _NSArrayCoreType, noCopy: Bool = default)</code>

    </div></div>
</div>
<div class="declaration" id="init-arrayliteral_">
<a class="toggle-link" data-toggle="collapse" href="#comment-init-arrayliteral_">init(<wbr>arrayLiteral:)</a><div class="comment collapse" id="comment-init-arrayliteral_"><div class="p">
    <p>Create an instance containing <code>elements</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init(arrayLiteral elements: T...)</code>

    </div></div>
</div>
<div class="declaration" id="init-count_repeatedvalue_">
<a class="toggle-link" data-toggle="collapse" href="#comment-init-count_repeatedvalue_">init(<wbr>count:<wbr>repeatedValue:)</a><div class="comment collapse" id="comment-init-count_repeatedvalue_"><div class="p">
    <p>Construct a Array of <code>count</code> elements, each initialized to
<code>repeatedValue</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init(count: Int, repeatedValue: T)</code>

    </div></div>
</div>


<h3>Instance Variables</h3>
<div class="declaration" id="var-capacity_-int">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-capacity_-int">var capacity: Int</a><div class="comment collapse" id="comment-var-capacity_-int"><div class="p">
    <p>How many elements the <code>Array</code> can store without reallocation</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var capacity: Int { get }</code>

    </div></div>
</div>
<div class="declaration" id="var-count_-int">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-count_-int">var count: Int</a><div class="comment collapse" id="comment-var-count_-int"><div class="p">
    <p>How many elements the Array stores</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var count: Int { get }</code>

    </div></div>
</div>
<div class="declaration" id="var-debugdescription_-string">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-debugdescription_-string">var debugDescription: String</a><div class="comment collapse" id="comment-var-debugdescription_-string"><div class="p">
    <p>A textual representation of <code>self</code>, suitable for debugging.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var debugDescription: String { get }</code>

    </div></div>
</div>
<div class="declaration" id="var-description_-string">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-description_-string">var description: String</a><div class="comment collapse" id="comment-var-description_-string"><div class="p">
    <p>A textual representation of <code>self</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var description: String { get }</code>

    </div></div>
</div>
<div class="declaration" id="var-endindex_-int">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-endindex_-int">var endIndex: Int</a><div class="comment collapse" id="comment-var-endindex_-int"><div class="p">
    <p>A &quot;past-the-end&quot; element index; the successor of the last valid
subscript argument.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var endIndex: Int { get }</code>

    </div></div>
</div>
<div class="declaration" id="var-first_-t">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-first_-t">var first: T?</a><div class="comment collapse" id="comment-var-first_-t"><div class="p">
    <p>The first element, or <code>nil</code> if the array is empty</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var first: T? { get }</code>

    </div></div>
</div>
<div class="declaration" id="var-isempty_-bool">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-isempty_-bool">var isEmpty: Bool</a><div class="comment collapse" id="comment-var-isempty_-bool"><div class="p">
    <p><code>true</code> if and only if the <code>Array</code> is empty</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var isEmpty: Bool { get }</code>

    </div></div>
</div>
<div class="declaration" id="var-last_-t">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-last_-t">var last: T?</a><div class="comment collapse" id="comment-var-last_-t"><div class="p">
    <p>The last element, or <code>nil</code> if the array is empty</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var last: T? { get }</code>

    </div></div>
</div>
<div class="declaration" id="var-startindex_-int">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-startindex_-int">var startIndex: Int</a><div class="comment collapse" id="comment-var-startindex_-int"><div class="p">
    <p>Always zero, which is the index of the first element when non-empty.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var startIndex: Int { get }</code>

    </div></div>
</div>

<h3>Subscripts</h3>
<div class="declaration" id="subscript-subscript_-int">
<a class="toggle-link" data-toggle="collapse" href="#comment-subscript-subscript_-int">subscript(_: Int)</a>
<div class="comment collapse" id="comment-subscript-subscript_-int"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">subscript(index: Int) -&gt; T</code>
    
    
</div></div>
</div>
<div class="declaration" id="subscript-subscript_-range-int">
<a class="toggle-link" data-toggle="collapse" href="#comment-subscript-subscript_-range-int">subscript(_: Range&lt;Int&gt;)</a>
<div class="comment collapse" id="comment-subscript-subscript_-range-int"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">subscript(subRange: Range&lt;Int&gt;) -&gt; ArraySlice&lt;T&gt;</code>
    
    
</div></div>
</div>


<h3>Instance Methods</h3>
<div class="declaration" id="func-append_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-append_">mutating func append(<wbr>_:)</a>
        
<div class="comment collapse" id="comment-func-append_"><div class="p">
    <p>Append newElement to the Array</p>

<p>Complexity: amortized O(1) unless <code>self</code>&#39;s storage is shared with another live array; O(<code>count</code>) if <code>self</code> does not wrap a bridged <code>NSArray</code>; otherwise the efficiency is unspecified.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">mutating func append(newElement: T)</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-extend_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-extend_">mutating func extend(<wbr>_:)</a>
        
<div class="comment collapse" id="comment-func-extend_"><div class="p">
    <p>Append the elements of <code>newElements</code> to <code>self</code>.</p>

<p>Complexity: O(<em>length of result</em>) </p>

    <h4>Declaration</h4>    
    <code class="language-swift">mutating func extend&lt;S : SequenceType where T == T&gt;(newElements: S)</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-filter_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-filter_">func filter(<wbr>_:)</a>
        
<div class="comment collapse" id="comment-func-filter_"><div class="p">
    <p>Return an <code>Array</code> containing the elements <code>x</code> of <code>self</code> for which
<code>includeElement(x)</code> is <code>true</code></p>

    <h4>Declaration</h4>    
    <code class="language-swift">func filter(includeElement: (T) -&gt; Bool) -&gt; [T]</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-flatmap_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-flatmap_">func flatMap(<wbr>_:)</a>
        
<div class="comment collapse" id="comment-func-flatmap_"><div class="p">
    <p>Return an <code>Array</code> containing the results of calling
<code>transform(x)</code> on each element <code>x</code> of <code>self</code> and flattening the result.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func flatMap&lt;U&gt;(transform: @noescape (T) -&gt; [U]) -&gt; [U]</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-generate">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-generate">func generate()</a>
        
<div class="comment collapse" id="comment-func-generate"><div class="p">
    <p>Return a <em>generator</em> over the elements.</p>

<p>Complexity: O(1)</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func generate() -&gt; IndexingGenerator&lt;[T]&gt;</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-getmirror">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-getmirror">func getMirror()</a>
        
<div class="comment collapse" id="comment-func-getmirror"><div class="p">
    <p>Returns a mirror that reflects <code>self</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func getMirror() -&gt; MirrorType</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-insert_atindex_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-insert_atindex_">mutating func insert(<wbr>_:<wbr>atIndex:)</a>
        
<div class="comment collapse" id="comment-func-insert_atindex_"><div class="p">
    <p>Insert <code>newElement</code> at index <code>i</code>.</p>

<p>Requires: <code>i &lt;= count</code></p>

<p>Complexity: O(<code>count</code>).</p>

    <h4>Declaration</h4>    
    <code class="language-swift">mutating func insert(newElement: T, atIndex i: Int)</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-join_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-join_">func join(<wbr>_:)</a>
        
<div class="comment collapse" id="comment-func-join_"><div class="p">
    <p>Interpose <code>self</code> between each consecutive pair of <code>elements</code>,
and concatenate the elements of the resulting sequence.  For
example, <code>[-1, -2].join([[1, 2, 3], [4, 5, 6], [7, 8, 9]])</code>
yields <code>[1, 2, 3, -1, -2, 4, 5, 6, -1, -2, 7, 8, 9]</code></p>

    <h4>Declaration</h4>    
    <code class="language-swift">func join&lt;S : SequenceType where [T] == [T]&gt;(elements: S) -&gt; [T]</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-map_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-map_">func map(<wbr>_:)</a>
        
<div class="comment collapse" id="comment-func-map_"><div class="p">
    <p>Return an <code>Array</code> containing the results of calling
<code>transform(x)</code> on each element <code>x</code> of <code>self</code></p>

    <h4>Declaration</h4>    
    <code class="language-swift">func map&lt;U&gt;(transform: (T) -&gt; U) -&gt; [U]</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-reduce_combine_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-reduce_combine_">func reduce(<wbr>_:<wbr>combine:)</a>
        
<div class="comment collapse" id="comment-func-reduce_combine_"><div class="p">
    <p>Return the result of repeatedly calling <code>combine</code> with an
accumulated value initialized to <code>initial</code> and each element of
<code>self</code>, in turn, i.e. return
<code>combine(combine(...combine(combine(initial, self[0]),
self[1]),...self[count-2]), self[count-1])</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func reduce&lt;U&gt;(initial: U, combine: @noescape (U, T) -&gt; U) -&gt; U</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-removeall_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-removeall_">mutating func removeAll(<wbr>_:)</a>
        
<div class="comment collapse" id="comment-func-removeall_"><div class="p">
    <p>Remove all elements.</p>

<p>Postcondition: <code>capacity == 0</code> iff <code>keepCapacity</code> is <code>false</code>.</p>

<p>Complexity: O(<code>count(self)</code>).</p>

    <h4>Declaration</h4>    
    <code class="language-swift">mutating func removeAll(keepCapacity: Bool = default)</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-removeatindex_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-removeatindex_">mutating func removeAtIndex(<wbr>_:)</a>
        
<div class="comment collapse" id="comment-func-removeatindex_"><div class="p">
    <p>Remove and return the element at index <code>i</code></p>

<p>Invalidates all indices with respect to <code>self</code>.</p>

<p>Complexity: O(<code>count</code>).</p>

    <h4>Declaration</h4>    
    <code class="language-swift">mutating func removeAtIndex(index: Int) -&gt; T</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-removelast">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-removelast">mutating func removeLast()</a>
        
<div class="comment collapse" id="comment-func-removelast"><div class="p">
    <p>Remove an element from the end of the Array in O(1).
Requires: count &gt; 0</p>

    <h4>Declaration</h4>    
    <code class="language-swift">mutating func removeLast() -&gt; T</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-removerange_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-removerange_">mutating func removeRange(<wbr>_:)</a>
        
<div class="comment collapse" id="comment-func-removerange_"><div class="p">
    <p>Remove the indicated <code>subRange</code> of elements</p>

<p>Complexity: O(<code>count</code>).</p>

    <h4>Declaration</h4>    
    <code class="language-swift">mutating func removeRange(subRange: Range&lt;Int&gt;)</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-replacerange_with_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-replacerange_with_">mutating func replaceRange(<wbr>_:<wbr>with:)</a>
        
<div class="comment collapse" id="comment-func-replacerange_with_"><div class="p">
    <p>Replace the given <code>subRange</code> of elements with <code>newElements</code>.</p>

<p>Complexity: O(<code>count(subRange)</code>) if <code>subRange.endIndex
== self.endIndex</code> and <code>isEmpty(newElements)</code>, O(N) otherwise.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">mutating func replaceRange&lt;C : CollectionType where T == T&gt;(subRange: Range&lt;Int&gt;, with newElements: C)</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-reservecapacity_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-reservecapacity_">mutating func reserveCapacity(<wbr>_:)</a>
        
<div class="comment collapse" id="comment-func-reservecapacity_"><div class="p">
    <p>Reserve enough space to store minimumCapacity elements.</p>

<p>PostCondition: <code>capacity &gt;= minimumCapacity</code> and the array has
mutable contiguous storage.</p>

<p>Complexity: O(<code>count</code>)</p>

    <h4>Declaration</h4>    
    <code class="language-swift">mutating func reserveCapacity(minimumCapacity: Int)</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-reverse">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-reverse">func reverse()</a>
        
<div class="comment collapse" id="comment-func-reverse"><div class="p">
    <p>A Array containing the elements of <code>self</code> in reverse order</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func reverse() -&gt; [T]</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-sort_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-sort_">mutating func sort(<wbr>_:)</a>
        
<div class="comment collapse" id="comment-func-sort_"><div class="p">
    <p>Sort <code>self</code> in-place according to <code>isOrderedBefore</code>.  Requires:
<code>isOrderedBefore</code> induces a <a href="http://en.wikipedia.org/wiki/Strict_weak_order#Strict_weak_orderings">strict weak ordering</a>
over the elements.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">mutating func sort(isOrderedBefore: (T, T) -&gt; Bool)</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-sorted_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-sorted_">func sorted(<wbr>_:)</a>
        
<div class="comment collapse" id="comment-func-sorted_"><div class="p">
    <p>Return a copy of <code>self</code> that has been sorted according to
<code>isOrderedBefore</code>.  Requires: <code>isOrderedBefore</code> induces a
<a href="http://en.wikipedia.org/wiki/Strict_weak_order#Strict_weak_orderings">strict weak ordering</a>
over the elements.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func sorted(isOrderedBefore: (T, T) -&gt; Bool) -&gt; [T]</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-splice_atindex_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-splice_atindex_">mutating func splice(<wbr>_:<wbr>atIndex:)</a>
        
<div class="comment collapse" id="comment-func-splice_atindex_"><div class="p">
    <p>Insert <code>newElements</code> at index <code>i</code></p>

<p>Invalidates all indices with respect to <code>self</code>.</p>

<p>Complexity: O(<code>count + count(newElements)</code>).</p>

    <h4>Declaration</h4>    
    <code class="language-swift">mutating func splice&lt;S : CollectionType where T == T&gt;(newElements: S, atIndex i: Int)</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-withunsafebufferpointer_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-withunsafebufferpointer_">func withUnsafeBufferPointer(<wbr>_:)</a>
        
<div class="comment collapse" id="comment-func-withunsafebufferpointer_"><div class="p">
    <p>Call <code>body(p)</code>, where <code>p</code> is a pointer to the <code>Array</code>&#39;s
contiguous storage. If no such storage exists, it is first created.</p>

<p>Often, the optimizer can eliminate bounds checks within an
array algorithm, but when that fails, invoking the
same algorithm on <code>body</code>&#39;s argument lets you trade safety for
speed.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func withUnsafeBufferPointer&lt;R&gt;(body: @noescape (UnsafeBufferPointer&lt;T&gt;) -&gt; R) -&gt; R</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-withunsafemutablebufferpointer_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-withunsafemutablebufferpointer_">mutating func withUnsafeMutableBufferPointer(<wbr>_:)</a>
        
<div class="comment collapse" id="comment-func-withunsafemutablebufferpointer_"><div class="p">
    <p>Call <code>body(p)</code>, where <code>p</code> is a pointer to the <code>Array</code>&#39;s
mutable contiguous storage. If no such storage exists, it is first created.</p>

<p>Often, the optimizer can eliminate bounds- and uniqueness-checks
within an array algorithm, but when that fails, invoking the
same algorithm on <code>body</code>&#39;s argument lets you trade safety for
speed.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">mutating func withUnsafeMutableBufferPointer&lt;R&gt;(body: @noescape (inout UnsafeMutableBufferPointer&lt;T&gt;) -&gt; R) -&gt; R</code>
    
    
</div></div>
</div>


